import Mock from "mockjs"
import hearts from '@/assets/icon/hearts-fill.png';
import shoucang from '@/assets/icon/shoucang.png';
import liaotian from '@/assets/icon/liaotian.png';
import chanpin from '@/assets/icon/chanpin2.png';

const bannerList = [{
    src: 'https://cdn7.axureshop.com/demo2024/2316006/images/%E9%A6%96%E9%A1%B5/u51.svg'
}, {
    src: 'https://img95.699pic.com/photo/40177/3638.jpg_wh860.jpg'
}, {
    src: 'https://img95.699pic.com/photo/50096/1855.jpg_wh300.jpg'
}]

const navList = [{
    src: hearts,
    name: '医学前沿',
    type: 'danger'
}, {
    src: shoucang,
    name: '病例分享',
    type: 'warning'
}, {
    src: liaotian,
    name: '活动论坛',
    type: 'primary'
}, {
    src: chanpin,
    name: '产品专区',
    type: 'success'
},]

const { articleList } = Mock.mock({
    'articleList|100': [{
        paraid: 'para' + '@id',
        title: '@ctitle(10, 15)',
        data: '@datetime("2024-MM-dd")',
        'tag|1': navList,
        desc: '@integer(60, 100)' + '次浏览',
        img: '@image("200x200","#f66","图片")',
        paragraph: '@cparagraph()',
    }],
})

// 获取轮播图
Mock.mock('/home/bannerList', 'post', (config) => {
    const req = JSON.parse(config.body)
    return {
        code: 200,
        message: '获取轮播图数据成功',
        data: {
            bannerList
        }
    }
})

// 获取导航
Mock.mock('/home/navList', 'post', (config) => {
    const req = JSON.parse(config.body)
    return {
        code: 200,
        message: '获取导航栏数据成功',
        data: {
            navList
        }
    }
})

// 获取文章列表
Mock.mock('/home/articleList', 'post', (config) => {
    const req = JSON.parse(config.body)
    return {
        code: 200,
        message: '获取文章列表数据成功',
        data: {
            articleList
        }
    }
})

// 获取文章
Mock.mock('/home/article', 'post', (config) => {
    const req = JSON.parse(config.body)
    // console.log(req);
    const data = {
        code: 200,
        message: '获取文章数据失败',
        data: {}
    }
    // console.log(req);
    for (let i = 0; i < articleList.length; i++) {
        if (articleList[i].paraid == req.paraid) {
            data.message = '获取文章数据成功'
            data.data = articleList[i]
            break
        }
    }
    return data
})

// 获取对应标签数据
Mock.mock('/home/tagArticleList', 'post', (config) => {
    const req = JSON.parse(config.body)
    const data = {
        code: 200,
        message: '获取标签数据失败',
        data: {}
    }
    // console.log(req);
    let arr = []
    for (let i = 0; i < articleList.length; i++) {
        if (articleList[i].tag.name == req.tag) {
            data.message = '获取标签数据成功'
            arr.push(articleList[i])
        }
    }
    data.data = arr
    return data
})